<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		
		<link rel="stylesheet" type="text/css" href="../../style.css" />
		
		<script type="text/javascript" src="../../navigation_menu.js"></script>
		<script type="text/javascript" src="../../validation.js"></script>
		
		<script type="text/javascript">
		    var djConfig = {
				isDebug:true,
				parseOnLoad:true,
				usePlainJson:true
		    };
		</script>
		 
		<script type="text/javascript" src="../../dojo/dojo/dojo.js"></script>
		<script type="text/javascript" src="../../dojo/dijit/dijit.js"></script>

		<script type="text/javascript">
    		dojo.require("dijit.form.Button");
    		dojo.require("dojo.rpc.JsonService");    	
    	</script>
		
		<script language="JavaScript" type="text/javascript">
			var makeShipperNoteService = new dojo.rpc.JsonService("MakeShipperNoteService?smd");
			
			//页面加载时的一些操作
			dojo.addOnLoad(load);
			function load() {
				menu_main('../../nav.xml', 'navigation_menu');
				initPage();
			}
			//得到当前日期
			function showDate() {
				var today = new Date();   
				var day = today.getDate();   
				var month = today.getMonth() + 1;   
				var year = today.getFullYear();   
				return year + "-" + month + "-" + day;
			}
			//初始化页面
			function initPage() {
				makeShipperNoteService.getOrderPlanID().addCallback(function (result) {
					document.getElementById("sn_num1").innerHTML = result;
					document.getElementById("sn_num2").innerHTML = result;
				});
				
				var cur_date = showDate();
			
				//上次更改日期为当前日期
				document.getElementById("sn_last_modified_date").innerHTML = cur_date;
	
				makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
					console.dir(AD);
					//发货人信息
					document.getElementById("sender").innerHTML = AD.commission.sender.name;
					document.getElementById("sender_contact").innerHTML = AD.commission.sender.customerContact.name;
					document.getElementById("sender_tel").innerHTML = AD.commission.sender.customerContact.OTel;
					document.getElementById("sender_fax").innerHTML = AD.commission.sender.customerContact.fax;
					//收货人信息
					document.getElementById("receiver").innerHTML = AD.commission.receiver.name;
					document.getElementById("receiver_contact").innerHTML = AD.commission.receiver.customerContact.name;
					document.getElementById("receiver_tel").innerHTML = AD.commission.receiver.customerContact.OTel;
					document.getElementById("receiver_fax").innerHTML = AD.commission.receiver.customerContact.fax;
					//通知人信息
					document.getElementById("notifier").innerHTML = AD.commission.notifier.name;
					document.getElementById("notifier_contact").innerHTML = AD.commission.notifier.customerContact.name;
					document.getElementById("notifier_tel").innerHTML = AD.commission.notifier.customerContact.OTel;
					document.getElementById("notifier_fax").innerHTML = AD.commission.notifier.customerContact.fax;

					//收货地点
					document.getElementById("receive_loc").innerHTML = AD.commission.receiveLoc;

					makeShipperNoteService.getOrderPlan().addCallback(function (orderPlan) {
						console.dir(orderPlan);
						//船次
						document.getElementById("scd_id").innerHTML = orderPlan.shipSchedule.id;
						//船名
						document.getElementById("ship_name").innerHTML = orderPlan.shipSchedule.shipInfo.name;
					});

					//装货港
					document.getElementById("departure").innerHTML = AD.commission.departure;
					//卸货港
					document.getElementById("unload_loc").innerHTML = AD.commission.destination;
					//目的港
					document.getElementById("destination").innerHTML = AD.commission.destination;
					//TO
					document.getElementById("shipcom_name").innerHTML = AD.commission.shipComInfo.fullTitle;

					//货物信息
					makeShipperNoteService.getBoxAndGoods(window.opener.document.getElementById("sn_id").value).addCallback(function (BAG) {
						console.dir(BAG);

						var bag = BAG.list;
						var totalBox = 0;
						var totalWeight = 0;
						var totalSize = 0;
						
						var text = "";
						text = text + "<table border='1'>";
						text = text + "    <tr><th>集装箱号</th><th>铅封号</th><th>箱数或件数</th><th>包装种类与货名</th><th>毛重(公斤)</th><th>尺码(立方米)</th></tr>";
						for (var i in bag) {
							text = text + "    <tr>";
							text = text + "        <td>" + bag[i].box.id +"</td>";
							text = text + "        <td>" + bag[i].box.leadSealing + "</td>";
							text = text + "        <td>" + bag[i].goodsNum + "</td>";
							text = text + "        <td>" + bag[i].goods.pack + ":" + bag[i].goods.name + "</td>";
							text = text + "        <td>" + bag[i].goods.weight * bag[i].goodsNum + "</td>";
							text = text + "        <td>" + bag[i].goods.size * bag[i].goodsNum + "</td>";
							text = text + "    </tr>";

							totalBox = totalBox + bag[i].goodsNum;
							totalWeight = totalWeight + bag[i].goods.weight * bag[i].goodsNum;
							totalSize = totalSize + bag[i].goods.size * bag[i].goodsNum;
						}
						//集装箱数或件数统计
						text = text + "<tr><th>集装箱数或件数统计</th><td colspan='5'>" + totalBox + " " + totalWeight + " " + totalSize + "</td></tr>";
						text = text + "</table>";
						document.getElementById("goods_info").innerHTML = text;
					});
					//费用信息
					makeShipperNoteService.getAllocDetails().addCallback(function (AD) {
						console.dir(AD);
	
						var commitedService = AD.commission.commitedService;
						makeShipperNoteService.getFeeItems().addCallback(function (feeItems) {
							console.dir(feeItems);
	
							var fee = feeItems.list;
							makeShipperNoteService.getBoxAndGoods(window.opener.document.getElementById("sn_id").value).addCallback(function (BAG) {
								console.dir(BAG);
	
								var bag = BAG.list;
								var weight = 0;
								for (var i in bag) {
									weight = weight + bag[i].goods.weight;
								}
								weight = weight * 1.0 / 1000;
								
								var text = "";
								text = text + "<table border='1'>";
								text = text + "    <tr><th>费用条目</th><th>费率</th><th>数量</th><th>费用</th><th>预付或到付</th></tr>";
	
								var rowCnt = 0;
								//一定有海运费
								for (var i in fee) {
									if (fee[i].name == "海运费") {
										text = text + "<tr><td>海运费</td><td>" + fee[i].std + fee[i].unitName + "</td><td>100海里, " + weight + "吨</td><td>" + fee[i].std * weight + "</td>";
										if (AD.commission.prePay == true) {
											text = text + "<td id='prePay'>预付</td>";
										} else {
											text = text + "<td id='prePay'>到付</td>";
										}
										text = text + "</tr>";
										rowCnt++;
										break;
									}
								}
								if (commitedService.declare == true) {				//报关费
									for (var i in fee) {
										if (fee[i].name == "报关费") {
											text = text + "<tr><td>报关费</td><td>" + fee[i].std + fee[i].unitName + "</td><td>1单</td><td>" + fee[i].std + "</td></tr>";
											rowCnt++;
											break;
										}
									}
								}
								if (commitedService.inspect == true) {				//报检费
									for (var i in fee) {
										if (fee[i].name == "报检费") {
											rowCnt++;
											break;
										}
									}
								}
								if (commitedService.insure == true) {				//保险费
									for (var i in fee) {
										if (fee[i].name == "保险费") {
											rowCnt++;
											break;
										}
									}
								}
								if (commitedService.store == true) {				//仓储费
									for (var i in fee) {
										if (fee[i].name == "仓储费") {
											rowCnt++;
											break;
										}
									}
								}
								if (commitedService.trail == true) {				//拖车费
									for (var i in fee) {
										if (fee[i].name == "拖车费") {
											rowCnt++;
											break;
										}
									}
								}
								
								text = text + "</table>";
								document.getElementById("fee_info").innerHTML = text;
								document.getElementById("prePay").rowSpan = rowCnt;
							});
						});
					});
					//运输方式
					document.getElementById("transport_terms").innerHTML = AD.commission.transportTerms;
					//货物种类
					document.getElementById("goods_type").innerHTML = AD.commission.goods.type;
					//冷藏温度
					if (AD.commission.goods.tempUnit != null) {
						document.getElementById("goods_temp").innerHTML = AD.commission.goods.temp;
					} else {
						document.getElementById("goods_temp").innerHTML = "常温";
					}
					//危险等级
					document.getElementById("goods_dangerclass").innerHTML = AD.commission.goods.dangerClass;
					//Property
					document.getElementById("goods_dangerproperty").innerHTML = AD.commission.goods.dangerProperty;
					//UN NO.
					document.getElementById("goods_unid").innerHTML = AD.commission.goods.UNID;
					//备注
					if (window.opener.document.getElementById("sn_comments") == null) {
						document.getElementById("comments").innerHTML = "";
					} else {
						document.getElementById("comments").innerHTML = window.opener.document.getElementById("sn_comments").value;
					}
					//装箱场站名称
					makeShipperNoteService.getCYInfo(window.opener.document.getElementById("cy_id").value).addCallback(function (CY) {
						console.dir(CY);
						document.getElementById("cy_name").innerHTML = CY.name;
					});
			
					//分船
					if (AD.commission.multiShip == true) {
						document.getElementById("multiship").innerHTML = "Y";
					} else {
						document.getElementById("multiship").innerHTML = "N";
					}
					//分批
					if (AD.commission.multiSchedule == true) {
						document.getElementById("multischedule").innerHTML = "Y";
					} else {
						document.getElementById("multischedule").innerHTML = "N";
					}
					//有效期
					document.getElementById("expiry_date").innerHTML = window.opener.document.getElementById("sn_date_of_expiry").value;
					//制单日期
					document.getElementById("init_date").innerHTML = cur_date;
				});
			}
			//订舱
			function order_box() {
				
			}
			//关闭
			function close_shipper_note() {
				window.close();
			}
			//返回
			function go_back() {
				window.opener.focus();
				window.close();
			}
		</script>
		
		<title>订舱</title>
	</head>

	<body>
		<!-- 导航菜单 -->
		<div id="navigation_menu" class="nav"></div>
		<div class="content">
			<h1>订舱</h1>
					
			<!-- 十联单明细 -->
			<div id="sn_details">
				<h4><a id="sn_num1"></a>号十联单明细</h4>
				<hr/>
				<table>
					<tr>
						<th>上次更改日期:</th><td id="sn_last_modified_date"></td>
						<th>第<a id="sn_num2"></a>号</th><td></td>
						<th>单据类型：</th><td><select><option>初始化单据</option></select></td>
					</tr>
				</table>
				<div><a href="#" onClick="order_box()">订舱</a> <a href="#" onClick="close_shipper_note()">关闭</a> <a href="#" onClick="go_back()">返回</a></div>
			</div>
			
			<!-- 单据 -->
			<div>
				<table border="1">
					<tr>
						<td>
							<table>
								<tr><th>发货人：</th><td id="sender"></td></tr>
								<tr><td>联系人：</td><td id="sender_contact"></td></tr>
								<tr><td>电话：</td><td id="sender_tel"></td></tr>
								<tr><td>传真：</td><td id="sender_fax"></td></tr>
							</table>
						</td>
						<td rowspan="5">
							<table>
								<tr><th>B/L NO.</th><td id="bl_id"></td></tr>
								<tr><td>TO:</td><td id="shipcom_name"></td></tr>
								<tr><td>FROM:</td><td>哈工大货代</td></tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table>
								<tr><th>收货人：</th><td id="receiver"></td></tr>
								<tr><td>联系人：</td><td id="receiver_contact"></td></tr>
								<tr><td>电话：</td><td id="receiver_tel"></td></tr>
								<tr><td>传真：</td><td id="receiver_fax"></td></tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table>
								<tr><th>通知人：</th><td id="notifier"></td></tr>
								<tr><td>联系人：</td><td id="notifier_contact"></td></tr>
								<tr><td>电话：</td><td id="notifier_tel"></td></tr>
								<tr><td>传真：</td><td id="notifier_fax"></td></tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table border="1">
								<tr>
									<th>前程运输</th><th>收货地点</th>
								</tr>
								<tr>
									<td></td><td id="receive_loc"></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table border="1">
								<tr>
									<th>船名</th><th>航次</th><th>装货港</th>
								</tr>
								<tr>
									<td id="ship_name"></td><td id="scd_id"></td><td id="departure"></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table border="1">
								<tr><th>卸货港</th><th>交货地点</th><th>目的港</th></tr>
								<tr><td id="unload_loc"></td><td></td><td id="destination"></td></tr>
							</table>
						</td>
					</tr>
					<tr>
						<td id="goods_info" colspan="2">
						</td>
					</tr>
					<tr>
						<td id="fee_info" colspan="2">
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table border="1">
								<tr>
									<th>兑换率</th><th>预付地点</th><th>到付地点</th><th>签发地点</th>
								</tr>
								<tr>
									<td rowspan="3" id="exchange_rate"></td><td id="prepay_loc"></td><td id="arrivepay_loc"></td><td id="sign_loc"></td>
								</tr>
								<tr>
									<th>预付总额</th><th>正本提单份数</th><th>货值金额</th>
								</tr>
								<tr>
									<td></td><td></td><td></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table border="1">
								<tr>
									<th>运输方式</th><th>货物种类</th><th>冷藏温度</th>
								</tr>
								<tr>
									<td id="transport_terms"></td><td id="goods_type"></td><td id="goods_temp"></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table>
								<tr><th rowspan="5">危险品</th></tr>
								<tr><th>Class:</th><td id="goods_dangerclass"></td></tr>
								<tr><th>Property:</th><td id="goods_dangerproperty"></td></tr>
								<tr><th>IMDG Code Page:</th><td></td></tr>
								<tr><th>UN No.:</th><td id="goods_unid"></td></tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table border="1">
								<tr>
									<th>发货人或代理人名称地址</th><th>联系人</th><th>电话</th>
								</tr>
								<tr>
									<td id="agent_name_addr">哈工大货代</td><td id="agent_contact">刘琳琳</td><td id="agent_tel">55740683</td>
								</tr>
							</table>
						</td>
						
					</tr>
					<tr>
						<td colspan="2">
							<table border="1">
								<tr>
									<th>可否转船</th><th>可否分批</th><th>装期</th>
									<td rowspan="6">
										<table border="1">
											<tr><th>备注</th><td id="comments"></td></tr>
										</table>
									</td>
									<td rowspan="6">
										<table border="1">
											<tr><th>装箱场站名称</th></tr>
											<tr><td id="cy_name"></td></tr>
										</table>
									</td>
								</tr>
								<tr>
									<td id="multiship"></td><td id="multischedule"></td><td id="load_date"></td>
								</tr>
								<tr>
									<th colspan="2">有效期</th><th>制单日期</th>
								</tr>
								<tr>
									<td colspan="2" id="expiry_date"></td><td id="init_date"></td>
								</tr>
								<tr>
									<td>海运费由</td><td></td><td>支付</td>
								</tr>
								<tr>
									<td colspan="3">如预付运费托收承付，请填准银行账号</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</div>
		</div>
	</body>
</html>
